<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="com.cqggrw.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>公共人物网后台管理</title>
<link type="text/css" rel="Stylesheet" href="../Content/tabbed_pages.css" />
<link type="text/css" rel="Stylesheet" href="../Content/Index.css" />
<script type="text/javascript" src="../../jslib/calendar.js"></script>
<script type="text/javascript" src="../../jslib/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="../../jslib/utils.js"></script>
<script type="text/javascript" src="../../jslib/ueditor/editor_config.js"></script>
<script type="text/javascript" src="../../jslib/ueditor/editor_all_min.js"></script>
<script type="text/javascript">
var editor = undefined;
$(function() {
	editor = new UE.ui.Editor();
	editor.render("myEditor");
	
	editor.ready(function(){
		editor.setContent('');
		editor.setHeight(250);
	//	alert(yy.getProjectPath());
	});
});
function WebForm_OnSubmit() {
	if($("#name").val() == '') {
		alert('请填写-新闻题目：');
		return false;
	} else if($("#type").val() == -1) {
		alert('请填写-新闻类型：');
		return false;
	} else if($("#addDate").val() == '') {
		alert('请填写-发布日期：');
		return false;
	} else if($("#addUser").val() == '') {
		alert('请填写-发布人：');
		return false;
	} else if(editor.getContent() == '') {
		alert('请填写-详细类容：');
		return false;
	}
	return true;
	
}

/*
 * 添加文件上传控件
 */
 function addImg(domObj) {
     var currentRow = $(domObj).parent("td").parent("tr");
     var newRow = currentRow.clone();
     var oldA = $(newRow.find("a:first").get(0));
     oldA.remove();
     var newA = "<a href='javascript:;', onclick='removeImg(this)'>[-]</a>";
     $(newRow.children(":first")).prepend(newA);
     currentRow.after(newRow);
     currentRow.parent().parent().find("input[type='file']").each(function(i) {
         $(this).attr("name", "img");
         $(this).prev().attr("name", "des");
     });
 }
 /*
 * 移除文件上传控件
 */
 function removeImg(domObj) {
     $(domObj).parent("td").parent("tr").remove();
 }
 
 function WebForm_DoPostBackWithOptions() {
	 var name = $('#name').val();
	 var txt = editor.getContent();
	
	 var start = 0;
	 var end = txt.indexOf('</p>', start);
	 while(true) {
		 if(end == -1) {
			 editor.setContent(txt);
			 break;
		 }
		 var tmp = txt.substring(start, end) + '</p>';
		 editor.setContent(tmp);
		 tmp = editor.getContentTxt();
		 tmp = tmp.replace(/ /g, "");
		 if(tmp != name && tmp.length > 40) {
			 $('#txtcontent').val(tmp);
			 editor.setContent(txt);
			 break;
		 }
		 
		 start = end + 4;
		 end = txt.indexOf('</p>', start);
	 }
 }
</script>
<style type="text/css">
.productImage {
	float: left;
	width: 200px;
	margin-left: 20px;
}

.productImage img {
	width: 200px;
	height: 150px;
}
</style>
</head>
<body>
	<form name="form1" method="post" action="newsAction!add.action" onsubmit="javascript:return WebForm_OnSubmit();" id="form1" enctype="multipart/form-data">
		<div class="form-div textLeft">
			<h1>
				<span class="action-span"><a href="NewList.jsp">新闻列表</a> </span> <span class="action-span1 fs20">公共人物网 管理中心 </span><span class="action-span1 paddingTop5"> - 新闻编辑 </span>
			</h1>
			<div style="clear:both"></div>
		</div>
		<div id="gallery">
			<div class="on" title="CommonInfo">
				<span>新闻信息</span>
			</div>
		</div>
		<div id="CommonInfo" class="show">
			<table width="90%" id="general-table" align="center">
				<tr>
					<td>新闻题目： <input name="name" type="text" maxlength="60" id="name" style="width:318px;" /> <span id="RequiredFieldValidator1" style="color:Red;visibility:hidden;">*</span></td>
				</tr>
				<tr>
					<td>新闻类型： <select name="type" id="type" MaxLength="30" style="height:20px;width:182px;">
							<option value="-1">请选择...</option>
							<%
								Connection conn = null;
								PreparedStatement ps = null;
								ResultSet rs = null;

								String sql = "SELECT * FROM tbl_category;";
								try {
									conn = DBUtil.getConn();
									ps = conn.prepareStatement(sql);
									rs = ps.executeQuery();

									while (rs.next()) {

										out.println("<option value=\"" + rs.getInt("id") + "\">" + rs.getString("name") + "</option>");
									}
								} catch (Exception e) {
									e.printStackTrace();
								} finally {
									DBUtil.close(conn, ps, rs);
								}
							%>
					</select> &nbsp;<span id="RequiredFieldValidator2" style="color:Red;visibility:hidden;">*</span></td>
				</tr>
				<tr>
					<td>发布日期： <input name="addDate" type="text" maxlength="10" id="addDate" /> <input name="selbtn1" type="button" id="selbtn1" onclick="new Calendar().show(this.form.addDate);" value="选择" class="button" /> <span id="RequiredFieldValidator4" style="color:Red;visibility:hidden;">*</span></td>
				</tr>
				<tr>
					<td>发&nbsp; 布&nbsp; 人：<input name="addUser" type="text" value="admin" maxlength="30" id="TextBoxReleaseName" readonly="readonly" /> &nbsp;<span id="RequiredFieldValidator3" style="color:Red;visibility:hidden;">*</span> 来源：<input name="comfrom" type="text" value="公共人物网" id="comfrom" /></td>
				</tr>
				<tr>
					<td>
						<table>
							<tr>
								<td>详细类容：</td>
								<td>
									<div>
										<textarea name="content" id="myEditor"></textarea>
									</div>
								</td>
							</tr>
						</table></td>
				</tr>
				<tr>
					<td>
						<table>
							<tr>
								<td>类容提取：</td>
								<td><textarea name="txtContent" rows="2" cols="20" id="txtcontent" style="height:95px;width:717px;">
</textarea> <input type="button" name="Button1" value="自动获取" onclick="javascript:WebForm_DoPostBackWithOptions()" id="Button1" />
								</td>
							</tr>
						</table></td>
				</tr>
				<tr>
					<td>文字属性： <input id="ckbIsPass" type="checkbox" value="1" name="ckbIsPass" checked="checked" /><label for="ckbIsPass">通过审核</label> :<input id="ckbtop" type="checkbox" value="1" name="ckbtop" /><label for="ckbtop">头条推荐</label><input id="cknishot" type="checkbox" value="1" name="cknishot" /><label for="cknishot">热点推荐</label></td>
				</tr>
				<tr>
					<td>新闻图片:
						<table style="margin-left:60px;">
							<tr>
								<td></td>
							</tr>
							<tr>
								<td>
									<a href="javascript:;" onclick="addImg(this)">[+]</a>  图片描述
									<input type="text" name="des" size="20" maxlength="50" /> 上传文件 <input type="file" name="img" id="file" /></td>
							</tr>
						</table></td>
				</tr>
			</table>
		</div>
		<div class="form-div textLeft" style="text-align:center;margin-top:5px;">
			<input type="submit" name="btnSave" value="保存" id="btnSave" class="button" />
		</div>
	</form>
</body>
</html>